//
//  CLCycleScollViewViewController.m
//  Charles
//
//  Created by Charles on 2017/2/7.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "CLCycleScollViewViewController.h"
#import "CycleScrollView.h"

@interface CLCycleScollViewViewController ()<CycleScrollViewDataSource, CycleScrollViewDelegate>{
    CycleScrollView *_minCycleScrollView;
    NSArray * array;
}

@end

@implementation CLCycleScollViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpData];
    [self setUpView];
}

- (void)setUpData {
    array = @[@"不限",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9+"];
}

- (void)setUpView {
    _minCycleScrollView = [self cycleScrollViewWithFrame:CGRectMake(0, 80, self.view.bounds.size.width , 44)];
    _minCycleScrollView.index = 0;
    _minCycleScrollView.dataSource = self;
    _minCycleScrollView.delegate = self;
}

- (CycleScrollView *)cycleScrollViewWithFrame:(CGRect)frame
{
    CycleScrollView *cycleScrollView = [[CycleScrollView alloc] initWithFrame:frame];
    [self.view addSubview:cycleScrollView];
    return cycleScrollView;
}

#pragma mark CycleScrollViewDataSource
- (NSInteger)numberOfRowsInCycleScrollView:(CycleScrollView *)cycleScrollView
{
    return array.count;
}

- (UIView *)cycleScrollView:(CycleScrollView *)cycleScrollView viewForRowAtIndex:(NSInteger)index
{
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cycleScrollView.bounds.size.width, cycleScrollView.bounds.size.height)];
    lable.font = [UIFont systemFontOfSize:16];
    lable.textColor = [UIColor colorWithRed:113.0 / 255.0 green:113.0 / 255.0 blue:113.0 / 255.0 alpha:1.0];
    lable.textAlignment = NSTextAlignmentCenter;
    lable.backgroundColor = [UIColor clearColor];
    lable.tag = index + 1;
    NSString *result = @"";
    if (index < array.count) {
        result = array[index];
    }
    lable.text = result;
    return lable;
}

#pragma mark CycleScrollView delegate
- (void)cycleScrollView:(CycleScrollView *)cycleScrollView didSelectedAtIndex:(NSInteger)index
{
    /**
     *  输出打印，选中的日期信息
     */
    NSLog(@"++++++select index is %@", array[index]);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
